import { plainMatrix } from '../math/index.js'
import { polarPoints, spiralPoints, ringPoints, rayPoints, gridCellPoints } from '../math/points/index.js'
import { _path2 } from './path2.js'
import { _transform } from '../math/transform.js'
import { _g } from './svg.js'
import { isometricPoints, polygonPoints } from '../math/points/polarPoints.js'

export const polarShape = (options, props) => {
    let points = polarPoints(options)
    let { pathMode, transform } = options

    // 变形函数
    points = _transform(points, transform)
    return _path2({
        ...options,
        points,
        mode: pathMode
    }, props)
}

export const spiralShape = (options, props) => {
    let { pathMode, transform } = options
    let matrix = spiralPoints(options).map(t => _transform(t, transform))
    let mirrorPoints = matrix[matrix.length - 1]
    let points = plainMatrix(matrix)

    return _path2({
        ...options,
        points,
        mode: pathMode,
        mirrorPoints
    }, props)
}

export const ringShape = (options, props) => {
    let { pathMode, transform } = options
    let matrix = ringPoints(options).map(t => _transform(t, transform))
    return _path2({
        ...options,
        points: matrix,
        mode: pathMode
    }, props)
}

export const rayShape = (options, props) => {
    let { pathMode, transform } = options
    let matrix = rayPoints(options).map(t => _transform(t, transform))
    return _path2({
        ...options,
        points: matrix,
        mode: pathMode
    }, props)
}

export const isometricShape = (options, props) => {
    let { pathMode, transform } = options
    let matrix = isometricPoints(options).map(t => _transform(t, transform))
    return _path2({
        ...options,
        points: matrix,
        mode: pathMode
    }, props)
}

// 多边形 迭代
export const polygonShape = (options, props) => {
    let matrix = []
    // let points = polygonPoints(options)
    // matrix.push(points)
    // 变形函数
    // points = _transform(points, transform)
    let { pathMode, transform, sweepFlag, n } = options

    for (let i = 0; i < n; i++) {
        let last = matrix[matrix.length - 1]
        let poinst = polygonPoints({
            ...options,
            o: last ? last[last.length - 1] : options.o,
            end: last ? last[0] : options.end,
            n: n - i,
            sweepFlag: i % 2
        })
        matrix.push(poinst)
    }

    matrix = matrix.map(t => _transform(t, transform))

    return _path2({
        ...options,
        points: matrix,
        mode: pathMode
    }, props)
}



export const gridShape = (options, props) => {
    let { pathMode, transform } = options
    let matrix = gridCellPoints(options)
    matrix = matrix.map(t => _transform(t, transform))
    // let points = plainMatrix(matrix)

    // points = _transform(points, transform)

    // let points = plainMatrix(gridCellPoints(options))
    // let { pathMode } = options
    return _path2({
        ...options,
        points: matrix,
        mode: pathMode
    }, props)
}
